/*
 * Tencent is pleased to support the open source community by making QMUI_Android available.
 *
 * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
 *
 * Licensed under the MIT License (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 * http://opensource.org/licenses/MIT
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

package hos.util.log;

import hos.core.AppCompat;
import hos.java.util.CrashUtils;

/**
 * <p>Title: PrintLog </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2020/1/8 20:12
 */
public class LogX {

    static final String TAG = "PrintLog";

    public interface LogDelegate {

        void d(final Object... contents);

        void dTag(final String tag, final Object... contents);

        void i(final Object... contents);

        void iTag(final String tag, final Object... contents);

        void w(final Object... contents);

        void wTag(final String tag, final Object... contents);

        void e(final Object... contents);

        void eTag(final String tag, final Object... contents);

        void file(final Object content);

        void file(final String tag, final Object content);

        void json(final Object content);

        void json(final String tag, final Object content);

        void xml(final String content);

        void xml(final String tag, final String content);

        default void printErrStackTrace(String tag, Throwable tr, final Object... obj) {
            CrashUtils.print(tr);
        }

        default boolean isDebug() {
            return AppCompat.isAppDebug();
        }

        default String processBody(final Object... contents) {
            return CrashUtils.processBody(contents);
        }
    }

    private static LogDelegate DELEGETE = null;

    public static void setDelegate(LogDelegate delegete) {
        DELEGETE = delegete;
    }

    public static void d(final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.d(contents);
        }
    }

    public static void dTag(final String tag, final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.dTag(tag, contents);
        }
    }

    public static void i(final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.i(contents);
        }
    }

    public static void iTag(final String tag, final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.iTag(tag, contents);
        }
    }

    public static void w(final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.w(contents);
        }
    }

    public static void wTag(final String tag, final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.wTag(tag, contents);
        }
    }

    public static void e(final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.e(contents);
        }
    }

    public static void eTag(final String tag, final Object... contents) {
        if (DELEGETE != null) {
            DELEGETE.eTag(tag, contents);
        }
    }


    public static void file(final Object content) {
        if (DELEGETE != null) {
            DELEGETE.file(content);
        }
    }

    public static void file(final String tag, final Object content) {
        if (DELEGETE != null) {
            DELEGETE.file(tag, content);
        }
    }

    public static void json(final Object content) {
        if (DELEGETE != null) {
            DELEGETE.json(content);
        }
    }

    public static void json(final String tag, final Object content) {
        if (DELEGETE != null) {
            DELEGETE.json(tag, content);
        }
    }

    public static void xml(final String content) {
        if (DELEGETE != null) {
            DELEGETE.xml(content);
        }
    }

    public static void xml(final String tag, final String content) {
        if (DELEGETE != null) {
            DELEGETE.xml(tag, content);
        }
    }

    public static void crash(Throwable e) {
        CrashUtils.print(e);
    }

}
